package com.biz.primus.ms.tms.api;

import com.biz.primus.common.vo.SpringPageVO;
import com.biz.primus.model.tms.enums.DeliveryPriority;
import com.biz.primus.model.tms.vo.*;
import com.biz.primus.ms.base.api.BaseApiController;
import com.biz.primus.ms.tms.service.DeliveryFeeService;
import com.biz.primus.ms.tms.service.DeliveryOrderService;
import com.biz.primus.ms.tms.service.LogisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * DeliveryApiController
 *
 * @author JKLiues
 * @date 2017/11/21
 */
@Api("配送单")
@RestController
@RequestMapping("soa/deliveryOrderService")
public class DeliveryApiController extends BaseApiController {
    private final DeliveryOrderService deliveryOrderService;
    private final DeliveryFeeService deliveryFeeService;
    private final LogisticsService logisticsService;

    @Autowired
    public DeliveryApiController(DeliveryOrderService deliveryOrderService, DeliveryFeeService deliveryFeeService, LogisticsService logisticsService) {
        this.deliveryOrderService = deliveryOrderService;
        this.deliveryFeeService = deliveryFeeService;
        this.logisticsService = logisticsService;
    }

    @ApiOperation("接单")
    @PostMapping("takeDeliverOrder")
    public void takeDeliverOrder(@RequestBody TmsLogisticsBaseReqVo reqVo) {
        logisticsService.takeDeliverOrder(reqVo);
    }

    @ApiOperation("取消接单")
    @PostMapping("cancelDelivery")
    public void cancelDelivery(@RequestBody TmsLogisticsBaseReqVo reqVo) {
        logisticsService.cancelDelivery(reqVo);
    }

    @ApiOperation("开始配送")
    @PostMapping("distribution")
    public void distribution(@RequestBody TmsLogisticsBaseReqVo reqVo) {
        logisticsService.distribution(reqVo);
    }

    @ApiOperation("确认到达")
    @PostMapping("arriveDestination")
    public void arriveDestination(@RequestBody TmsLogisticsBaseReqVo reqVo) {
        logisticsService.arriveDestination(reqVo);
    }

    @ApiOperation("完成(签收)")
    @PostMapping("finishOrder")
    public void finishOrder(@RequestBody FinishOrderReqVo reqVo) {
        logisticsService.finishOrder(reqVo);
    }

    @ApiOperation("查询配送单")
    @PostMapping("getDeliveryOrder")
    public List<DeliveryOrderVo> getDeliveryOrder(@RequestBody DeliverOrderListReqVo reqVo) {
        return deliveryOrderService.getDeliveryOrder(reqVo);
    }


    @ApiOperation("获取配送单数量")
    @PostMapping("getOrderNum")
    public List<OrderNumVo> getOrderNum(@RequestBody UserIdReqVo reqVo) {
        return deliveryOrderService.getOrderNum(reqVo);
    }

    @ApiOperation("获取配送单应签收的商品及其数量")
    @PostMapping("getSignProducts")
    public List<OrderInfoItemRespVo> getSignProducts(@RequestBody BaseTmsReqVo reqVo) {
        return deliveryOrderService.getSignProducts(reqVo);
    }

    @ApiOperation("获取已签收配送单签收商品及数量")
    @PostMapping("getSignedInfo")
    public OrderSignInfoRespVo getSignedInfo(@RequestBody BaseTmsReqVo reqVo) {
        return deliveryOrderService.getSignedInfo(reqVo);
    }

    @ApiOperation("获取商品订单价格")
    @PostMapping("getOrderPrice")
    public OrderPriceRespVo getOrderPrice(@RequestBody OrderPriceReqVo reqVo) {
        return deliveryOrderService.getOrderPrice(reqVo);
    }

    @ApiOperation("后台获取配送单详情")
    @PostMapping("getDeliveryDetail")
    public DeliveryDetailRespVo getDeliveryDetail(@ApiParam("配送单ID") @RequestParam("deliveryId") Long deliveryId) {
        return deliveryOrderService.getDeliveryDetail(deliveryId);
    }

    @ApiOperation("后台配送单查询")
    @PostMapping("searchPageDelivery")
    public SpringPageVO<DeliverySearchRespVo> searchPageDelivery(@RequestBody DeliverySearchReqVo reqVo) {
        return deliveryOrderService.searchPageDelivery(reqVo);
    }

    @ApiOperation("鹰眼轨迹")
    @GetMapping("getMaps")
    public List<LongitudeAndLatitudeVo> getMaps(@ApiParam("名称") @RequestParam("entityName") String entityName,
                                                @ApiParam("开始时间") @RequestParam("entityName") String startDate,
                                                @ApiParam("结束时间") @RequestParam("entityName") String endDate) {
        return deliveryOrderService.getMaps(entityName, startDate, endDate);
    }


    @ApiOperation("添加,修改对应价格")
    @PostMapping("updatePrice")
    public void update(@RequestBody DeliveryFeeVo reqVo) {
        deliveryFeeService.update(reqVo);
    }

    @ApiOperation("删除")
    @PostMapping("deletePrice")
    public void delete(@ApiParam("配送费配置ID") @RequestParam("id") Long id) {
        deliveryFeeService.delete(id);
    }

    @ApiOperation("根据id查询对应配送价格数据")
    @GetMapping("findPrice")
    public DeliveryFeeVo findPrice(@ApiParam("配送费配置ID") @RequestParam("id") Long id) {
        return deliveryFeeService.findPrice(id);
    }

    @ApiOperation("根据id查询对应配送价格数据")
    @GetMapping("getDeliverFee")
    public DeliveryFeeVo getDeliverFee(@ApiParam("配送优先级") @RequestParam("priority") DeliveryPriority priority) {
        return deliveryFeeService.getDeliverFee(priority);
    }
}
